import 'package:dk_flutter_base/dk_ui.dart';
import 'package:dk_flutter_base/dk_core.dart';
import 'dart:ui';

class RefreshNavigationBarEvent {
  double offset;
  RefreshNavigationBarEvent({this.offset});
}

class TopDynamicHeightWidget extends StatefulWidget {
  final double offset;
  final EventBus eventBus;
  TopDynamicHeightWidget({this.offset = 0,this.eventBus});
  @override
  _TopDynamicHeightWidgetState createState() => _TopDynamicHeightWidgetState(offset: this.offset,eventBus: this.eventBus);
}

class _TopDynamicHeightWidgetState extends State<TopDynamicHeightWidget> {
  double offset;
  final EventBus eventBus;
  _TopDynamicHeightWidgetState({this.offset,this.eventBus});
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    this.eventBus.on<RefreshNavigationBarEvent>().listen((RefreshNavigationBarEvent event){
      setState(() {
        this.offset = event.offset;
      });
    });
  }
  @override
  Widget build(BuildContext context) {
    double safeTop = MediaQueryData.fromWindow(window).padding.top;
    double navHeight = 0;
    if(this.offset < 0) {
      navHeight = -this.offset;
    }
    return Container(
      padding: EdgeInsets.only(top: safeTop),
      height: navHeight,
      decoration: BoxDecoration(
        color: Color(0xFF3274F9),
        border: Border(
          bottom: BorderSide(color: Color(0xFF3274F9),width: 0),
        ),
      ),
    );
  }
}

class NavigationBar extends StatelessWidget {
  final double topBarOpacity;
  NavigationBar({this.topBarOpacity = 1});
  @override
  Widget build(BuildContext context) {
    double safeTop = MediaQueryData.fromWindow(window).padding.top;
    double navHeight = safeTop + 44.0;
    return Opacity(
      opacity: this.topBarOpacity,
      child: Container(
        height: navHeight,
        color: Color(0xFF3274F9),
        child: Center(
          child: Padding(
            padding: EdgeInsets.only(top: safeTop),
            child: Text(
              "我的",
              style: TextStyle(
                fontWeight:FontWeight.w500,
                  fontSize:17,
                  color: Colors.white
              ),
            ),
          ),
        ),
      ),
    );
  }
}

